package com.zhuss.core.menu;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.permission.CareResourcePermissionListBo;
import com.zhuss.bean.bo.core.resource.DetailResourceBo;
import com.zhuss.bean.bo.core.resource.ListMenuTreeBo;
import com.zhuss.bean.bo.core.resource.ListResourceTreeBo;
import com.zhuss.bean.bo.core.resource.SearchResourceBo;
import com.zhuss.bean.vo.core.permission.ListPermissionTreeBean;
import com.zhuss.bean.vo.core.resource.CareResourcePermissionListVo;
import com.zhuss.bean.vo.core.resource.DetailResourceVo;
import com.zhuss.common.ReadService;
import com.zhuss.core.processor.PermissionRead;
import com.zhuss.core.processor.PermissionResourceRead;
import com.zhuss.core.processor.ResourceRead;
import com.zhuss.exception.AabException;


/**
 * 菜单资源点查询service（基本查询）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("resourceReadService")
public class ResourceReadService implements ReadService<Object, Object> {
	
	@Autowired
	@Qualifier("resourceRead")
	private ResourceRead resourceRead;
	
	@Autowired
	@Qualifier("permissionRead")
	private PermissionRead permissionRead;
	
	@Autowired
	@Qualifier("permissionResourceRead")
	private PermissionResourceRead permissionResourceRead;
	
	/**
	 * 详情
	 */
	@Override
	public Object detail(Object param) throws AabException {
		DetailResourceBo bo = (DetailResourceBo) param;
		Long resourceId = bo.getResourceId();
		Object vo = resourceRead.detail(resourceId);
		return vo;
	}
	
	/**
	 * 列表
	 */
	@Override
	public Object list(Object param) throws AabException {
		SearchResourceBo bo = (SearchResourceBo) param;
		Object result = resourceRead.list(bo);
		return result;
	}
	
	/**
	 * 菜单树
	 * @param bo
	 * @return
	 */
	protected Object listMenuTree(ListMenuTreeBo bo) {
		
		Integer system = bo.getSystem();
		return resourceRead.listMenuTree(system);
	}
	
	/**
	 * 菜单资源混合树
	 * @param bo
	 * @return
	 */
	protected Object listResourceTree(ListResourceTreeBo bo) {
		
		Integer system = bo.getSystem();
		return resourceRead.listResourceTree(system);
	}
	
	
	/**
	 * 菜单资源的的权限点树列表
	 * @param bo
	 * @return
	 * @throws AabException 
	 */
	@SuppressWarnings("unchecked")
	public Object careResourcePermissionList(CareResourcePermissionListBo bo) throws AabException {
		
		Long resourceId = bo.getResourceId();
		Integer system = ((DetailResourceVo) resourceRead.detail(resourceId)).getSystem();
		CareResourcePermissionListVo result = new CareResourcePermissionListVo();
		result.setPermissionIdList((List<Long>)permissionResourceRead.listPermissionId(resourceId));
		result.setPermissionTreeList((List<ListPermissionTreeBean>)permissionRead.listPermissionTreeBean(system));
		return result;
	}
	
	
	
}

